import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'

// 优化后的 Vite 配置（代码分割版本）
export default defineConfig({
  plugins: [vue()],
  base: process.env.NODE_ENV === 'production' ? '/coolv/vfs/root/products/ebi/sys/coolrpt/coolresource/' : '/',
  server: {
    port: 5173,
    proxy: {
      '/api': {
        target: 'http://localhost:8080',
        changeOrigin: true
      }
    }
  },
  build: {
    rollupOptions: {
      output: {
        // 手动代码分割
        manualChunks: {
          // Vue 核心库单独打包
          'vue-vendor': ['vue'],
          
          // 如果使用了 echarts，单独打包
          // 'echarts': ['echarts'],
          
          // 组件按功能分组
          'components-score': [
            './src/components/ComprehensiveScoreTest.vue',
            './src/components/ScoreDetailPage.vue',
            './src/components/BranchDetailPage.vue'
          ],
          
          'components-business': [
            './src/components/BusinessGrowth.vue',
            './src/components/BusinessCategory.vue',
            './src/components/BusinessComparison.vue',
            './src/components/BusinessRanking.vue'
          ],
          
          'components-common': [
            './src/components/MapComponent.vue',
            './src/components/KeyIndicators.vue',
            './src/components/RiskRadar.vue'
          ]
        }
      }
    },
    
    // 调整警告阈值为 1MB
    chunkSizeWarningLimit: 1000
  },
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src')
    }
  }
})

